import { Injectable, UnauthorizedException } from '@nestjs/common'
import { PassportStrategy } from '@nestjs/passport'
import { ExtractJwt, Strategy } from "passport-jwt"
import { UserService } from '../user/user.service'
import { jwtConstants } from "@constants/jwt.constant";

@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
    constructor() {
        super({
            jwtFromRequest: ExtractJwt.fromHeader('access_token'), //使用ExtractJwt.fromHeader从header获取token,
            ignoreExpiration: false,
            secretOrKey: jwtConstants.secret
        })
    }

    async validate(payload: any) {
        console.log('jwt---validate,', payload)
        // 这里会拿到模块解析token之后的用户信息（如果一切正常的话）
        return payload;
    }
}
